// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';

class GoodsInfoModel {
  ///商品ID
  final int id;

  ///类目ID
  final int cId;

  ///特征,特点,品质
  final String characteristic;

  ///原价
  final double originalPrice;

  ///现价
  final double price;
  final String name;
  final String pic;

  ///优惠活动
  String activity;

  ///购买数量
  int buyNum;

  GoodsInfoModel(
    this.id,
    this.cId,
    this.characteristic,
    this.originalPrice,
    this.price,
    this.name,
    this.pic,
    this.activity, {
    this.buyNum = 0,
  });

  GoodsInfoModel copyWith({
    int? id,
    int? cId,
    String? characteristic,
    double? originalPrice,
    double? price,
    String? name,
    String? pic,
    String? active,
    int buyNum = 0,
  }) {
    return GoodsInfoModel(
      id ?? this.id,
      cId ?? this.cId,
      characteristic ?? this.characteristic,
      originalPrice ?? this.originalPrice,
      price ?? this.price,
      name ?? this.name,
      pic ?? this.pic,
      active ?? this.activity,
      buyNum: buyNum,
    );
  }

  Map<String, dynamic> toMap() {
    return <String, dynamic>{
      'cId': cId,
      'id': id,
      'characteristic': characteristic,
      'originalPrice': originalPrice,
      'price': price,
      'name': name,
      'pic': pic,
      'active': activity,
      'buyNum': buyNum,
    };
  }

  factory GoodsInfoModel.fromMap(Map<String, dynamic> map) {
    return GoodsInfoModel(
      map['cId'] as int,
      map['id'] as int,
      map['characteristic'] as String,
      map['originalPrice'] as double,
      map['price'] as double,
      map['name'] as String,
      map['pic'] as String,
      map['active'] as String,
      buyNum: map['buyNum'] as int,
    );
  }

  String toJson() => json.encode(toMap());

  factory GoodsInfoModel.fromJson(String source) =>
      GoodsInfoModel.fromMap(json.decode(source) as Map<String, dynamic>);

  @override
  String toString() {
    return 'GoodsInfoModel(id: $id, cId: $cId, characteristic: $characteristic, originalPrice: $originalPrice, price: $price, name: $name, pic: $pic, active: $activity)';
  }

  @override
  bool operator ==(covariant GoodsInfoModel other) {
    if (identical(this, other)) return true;

    return other.cId == cId &&
        other.id == id &&
        other.characteristic == characteristic &&
        other.originalPrice == originalPrice &&
        other.price == price &&
        other.name == name &&
        other.pic == pic;
  }

  @override
  int get hashCode {
    return cId.hashCode ^
        id.hashCode ^
        characteristic.hashCode ^
        originalPrice.hashCode ^
        price.hashCode ^
        name.hashCode ^
        pic.hashCode;
  }
}
